package com.cta.jms;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

public class MessageProducer {

	private static final Logger LOG = LoggerFactory
			.getLogger(MessageProducer.class);

	protected JmsTemplate jmsTemplate;
	

	public void sendMessages(final String payload) throws JMSException {

		jmsTemplate.send(new MessageCreator() {

			public Message createMessage(Session session) throws JMSException {

				TextMessage message = session.createTextMessage(payload);

				LOG.info("Process and Sending message number {}" ,payload);

				return message;

			}

		});

	}


	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}
}
